#include "../includes/user.h"
#include "../includes/usercollection.h"
#include "../qusersdialog.h"
#include "../includes/progressitem.h"

#include <QApplication>

#include <QDate>

int main(int argc, char* argv[]) {
	QApplication app(argc, argv);

	UserCollection uc;

        // UserCollection saving/loading tests
        User u1("Ronen Agranat");
        User u2("Sarah Palser");
        User u3("Lawrence Webley");
        uc << u1 << u2 << u3;

        uc.save("test_output.xml");

        uc.clear();
        uc.load("test_output.xml");
        uc.save("test_output1.xml");

        // ProgressItem saving/loading tests
        ProgressItem p;
        p.setPhraseName("Baby");
        p.setStatus(ProgressItem::Learnt);
        u1.addProgressItem(p);
        QDomDocument doc("progress");
        QDomElement root = doc.createElement("progress");
        doc.appendChild(root);
        QDomElement progressItemElement = doc.createElement("progress_item");
        p.toDomElement(progressItemElement);
        root.appendChild(progressItemElement);
        QFile file("progress_test.xml");
        file.open(QFile::WriteOnly);
        QTextStream out(&file);
        doc.save(out, 0);
        file.close();

        uc.clear();
        uc << u1 << u2 << u3;
        uc.save("test_output2.xml");

	QUsersDialog *usersDialog = new QUsersDialog();
	usersDialog->setUserCollection(&uc);
	usersDialog->show();

        // need to use helper class to have collection change trigger save.
        // this belongs with the parent widget.
        // for now, hook up changed() notification to save as test file
        QObject::connect(usersDialog, SIGNAL(userCollectionChanged()), usersDialog, SLOT(saveTest()));

	return app.exec();
}
